<template>
  <div>
    <!-- 填写指导记录 -->
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item prop="progress" label="进展情况">
        <el-input v-model="form.progress"></el-input>
      </el-form-item>
      <el-form-item prop="desc" label="指导内容">
        <el-input :rows="10" type="textarea" v-model="form.desc"></el-input>
      </el-form-item>
      <el-form-item prop="comment" label="教师评语">
        <el-input v-model="form.comment"></el-input>
      </el-form-item>
      <el-button @click="send()">发送</el-button>
      <el-button @click="goback()">返回</el-button>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        progress: "",
        desc: "",
        comment: "",
      },
      rules: {
        progress: { required: true, message: "必填", trigger: "blur" },
        desc: { required: true, message: "必填", trigger: "blur" },
        comment: { required: true, message: "必填", trigger: "blur" },
      },
    };
  },
  methods: {
    goback() {
      this.$router.go(-1);
    },
    send() {
      const n = window.location.hash.substring(27);
      this.$refs.form.validate((valid) => {
        if (!valid) return;
        this.$http
          .post(
            "http://127.0.0.1:8080/teacher/writeRecord?student_num=" + n,
            this.$qs.stringify(this.form)
          )
          .then((res) => {
            // console.log(res);
            if (res.data.status == 0) {
              this.$message.success(res.data.message);
              this.form = {};
            } else {
              this.$message.error(res.data.message);
            }
          })
          .catch((err) => {
            this.$message.error(err);
          });
      });
    },
  },
};
</script>
<style lang="less" scoped>
// button {
//   position: absolute;
//   right: 40px;
// }
</style>
